<template>
    <el-dialog title="回复评论" v-model="visible" :width="500" destroy-on-close @closed="$emit('closed')">
        <el-form :model="form" :rules="rules" ref="dialogForm" label-width="100px" label-position="right">
            <el-form-item label="评论内容">{{ comment.content }}</el-form-item>
            <el-form-item label="回复内容" prop="content">
                <el-input v-model="form.content" clearable type="textarea"></el-input>
            </el-form-item>
        </el-form>
        <template #footer>
            <el-button @click="visible = false">取 消</el-button>
            <el-button type="primary" :loading="isSaveing" @click="submit()">保 存</el-button>
        </template>
    </el-dialog>
</template>

<script>
export default {
    emits: ['success', 'closed'],
    data () {
        return {
            visible: false,
            isSaveing: false,
            comment: {},
            //表单数据
            form: {
                content: ""
            },
            //验证规则
            rules: {
                content: [
                    { required: true, message: '请输入回复内容' }
                ]
            }
        }
    },
    mounted () {

    },
    methods: {
        //显示
        open () {
            this.visible = true;
            return this
        },
        //表单提交方法
        submit () {
            this.$refs.dialogForm.validate(async (valid) => {
                if (valid) {
                    this.isSaveing = true;
                    this.$API.app.activity.comment.reply.post(this.comment.id, this.form)
                        .then(() => {
                            this.$emit('success')
                            this.visible = false;
                            this.isSaveing = false;
                            this.$message.success("操作成功")
                        })
                }
            })
        },

        setData (data) {
            this.comment = data
        }
    }
}
</script>

<style></style>
